  // 用 new Image().src做Log 统计
  var unique = (function() {
	  var time = (new Date()).getTime() + '-';
	  var i = 0;
	  return function() {
		  return time + (i++);
	  }
  } ());
  var imgLog = function( url ) {
	  var data = window['imgLogData'] || (window['imgLogData'] = {});
	  var img = new Image();
	  var uid = unique();
	  img.onload = img.onerror = function() {
		  img.onload = img.onerror = null;
		  img = null;
		  delete data[uid];
	  }
	  img.src = url + '&_uid=' + uid;
  }
  
  
  
  // 闭包 函数缓存
  var mult = (function() {
	  var cache = {};
	  return function() {
		  var args = Object.prototype.toString.call( arguments, ',');
		  if (args in cache) {
			  return cache[args];
		  }
		  var a = 1;
		  for (var i = 0, l = arguments.length; i < l; i++) {
			  a = a * arguments[i];
		  }
		  return cache[args] = a;
	  }
  } ())
  
  // 提炼
  var mult = (function() {
	  var cache = {};
	  var calculate = function() {
		  var a = 1;
		  for (var i = 0, l = arguments.length; i < l; i++) {
			  a = a * arguments[i];
		  }
		  return a;
	  }
	  return function() {
		  var args = Object.prototype.toString.call(arguments, ',');
		  if (args in cache) {
			  return cache[args];
		  }
		  return cache[args] = calculate.apply(null, arguments);
	  }
  } ());
  
  // img对象常用于进行数据上传
  var report = function(src) {
	  var img = new Image();
	  img.src = src;
  };
  
  report( 'http://xxx.com/getUserInfo');
  
  // 延续局部变量的寿命
  var report = (function(src) {
	  var imgs = [];
	  return function() {
		  var img = new Image();
		  imgs.push(img);
		  img.src = src;
	  }
  }());
  
  //闭包 和 面向对象设计
  //闭包
  var extent = function() {
	  var value = 0;
	  return {
		  call: function() {
			  value ++;
			  console.log(value);
		  }
	  }
  };
  
  var extent = extent();
  extent.call(); // 1
  extent.call(); // 2
  extent.call(); // 3
  
  
  // 对象写法
  var extent = {
	  value: 0,
	  call: function() {
		  this.value ++;
		  console.log(this.value);
	  }
  }
  
  extent.call(); // 1
  extent.call(); // 2
  extent.call(); // 3
//或者
var Extent = function() {
	this.value = 0;
}
Extent.prototype.call = function() {
	this.value++;
	console.log( this.value )
};

var extent = new Extent();
extent.call();
extent.call();
extent.call();

// 闭包实现命令模式
<html>
<body>
<button id="execute">点击我执行命令</button>
<button id="undo">点击我执行命令</button>
</body>
<script>
var Tv = {
	open: function() {
		console.log('打开电视机');
	}，
	close: function() {
		console.log('关闭电视机');
	}
}
var OpenTvCommand = function( receiver ) {
	this.receiver = recerver;
}
OpenTvCommand.prototype.execute = function() {
	this.recerver.open();
}
OpenTvCommand.prototype.undo = function() {
	this.receiver.close();
}

var setCommand = function( command ) {
	document.getElementById('execute').onclick = function() {
		command.execute();
	}
	document.getElementById('undo').onclick = function() {
		command.undo();
	}
}

setCommand( new OpenTvCommand(Tv) );

///////////////////////////////////////////////////////////////
// 闭包
var Tv = {
	open: function() {
		console.log('打开电视机');
	},
	close: function() {
		console.log('关上电视机');
	}
}

var createCommend = function( receiver ) {
	var execute = function() {
		return receiver.open();
	}
	var undo = function() {
		return receiver.close();
	}
	return {
		execute: execute,
		undo: undo
	}
}
var setCommand = function( command ) {
	document.getElementById('execute').onclick = function() {
		command.execute();
	}
	document.getElementById('undo').onclick = function() {
		command.undo();
	}
}

setCommand( createCommend(Tv) );


if(!String.prototype.format ){
	String.prototype.format = function() {
	var e = arguments;
	return this.replace(/{(d+)}/g,function(t, n) {
		return typeof e[n] != "undefined" ? e[n] : t;
	})
	};
}
/////////////////////////////////////////////


let en = {
	title: 'Tesra'
}
let ch = {
	title: '超算网络'
}


///////////////////////////////////////////////
// button
localStorage.setItem('language', 0)


//
let lanType = localStorage.getItem('language');
let language = lanType ? ch : en;



language.title



</script>
</html>
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  